package com.monkey.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * desc:
 * auth: chenxiaobin
 * data: 2017/3/29.
 */
@Component
public class WebConfig {
    private static Logger logger = LoggerFactory.getLogger(WebConfig.class);

    private Properties properties;

    public WebConfig() {
        properties = new Properties();
        InputStream resourceAsStream = null;
        try {
            resourceAsStream = WebConfig.class.getClassLoader().getResourceAsStream("webconfig.properties");
            properties.load(resourceAsStream);
        } catch (IOException e) {
            logger.error("read webconfig.properties error", e);
        } finally {
            if (null != resourceAsStream) {
                try {
                    resourceAsStream.close();
                } catch (IOException e) {
                    logger.error("parse webconfig.properties error", e);
                }
            }
        }
    }

    public String get(String key) {
        return (String) properties.get(key);
    }

    public int getInt(String key) {
        return Integer.valueOf((String) properties.get(key));
    }

    public float getFloat(String key) {
        return Float.valueOf((String) properties.get(key));
    }
}
